package com.chen.dao;

import com.chen.model.Contract;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface ContractDao {

    List<Contract> findAllContract();

    int addContract(Contract contract);

    @Select("select * from contract where contract_id=#{contract_id}")
    @Results({
            @Result(id = true, column="contract_id",property = "contract_id" ),
            @Result(column="contract_message",property = "contract_message" ),
            @Result(column="contract_state",property = "contract_state" ),
            @Result(column="contract_time",property = "contract_time" ),
            @Result(column="customer_id",property="customer",
                    one=@One(select="com.chen.dao.CustomerDao.findCustomerById",fetchType= FetchType.EAGER)),
            @Result(column="salesman_id",property="salesman",
                    one=@One(select="com.chen.dao.SalesmanDao.findSalesmanById",fetchType= FetchType.EAGER)),
    })
    Contract findContractById(Integer contract_id);

    @Update("update contract set contract_message=#{contract_message},contract_time=#{contract_time} where contract_id=#{contract_id}")
    int updateContract(Contract contract);

    @Update("update contract set contract_state=#{contract_state} where contract_id=#{contract_id}")
    int updateState(Contract contract);
}
